import { ItemData } from "../Datas/Data";
import { Constant, ItemType } from "../Framework/Const/Constant";
import AudioManager from "../Framework/Managers/AudioManager";
import { PoolManager } from "../Framework/Managers/PoolManager";
import { UIManager } from "../Framework/Managers/UIManager";
import NodeUtil from "../Framework/Utils/NodeUtil";
import GoodsItem from "./GoodsItem";
const { ccclass, property } = cc._decorator;

@ccclass
export default class RewardPanel extends cc.Component {
    Panel: cc.Node = null;
    Content: cc.Node = null;
    goodsItem: cc.Node = null;

    protected onLoad(): void {
        this.Panel = NodeUtil.GetNode("Panel", this.node);
        this.Content = NodeUtil.GetNode("Content", this.node);
    }

    Show(data: ItemData) {
        if (this.goodsItem) PoolManager.PutNode(this.goodsItem);
        PoolManager.GetNode("Prefabs/UI/GoodsItem", this.Content).then((node) => {
            this.goodsItem = node;
            let goods = node.getComponent(GoodsItem);
            goods.Init(data, () => { });
        });
    }

    OnButtonClick(event: cc.Event) {
        AudioManager.PlayAudio(Constant.Audio.ButtonClick);

        switch (event.target.name) {
            case "Mask":
                UIManager.Instance.HidePanel(Constant.Panel.RewardPanel);
                break;
        }
    }
}
